<?php

namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Db;
use think\Session;


class Villa extends Controller
{
    /**
     * 显示二级列表页(别墅分页之首页)
     *
     * @return \think\Response
     */
    public function index()
    {
        //从数据库导出导航条数据
        $list = Db::name('index_navigation')->select();
        //从数据库里查询友情链接
        $data = Db::table('lt_link')->select();

        //从房屋详情表中取出房屋数据
        $housedetails = Db::table('lt_house_details')->where('housetype','41')->where('checking','<>','2')->select();

        if(is_mobile()){
            //显示手机端
            return view('villa/Mindex',[
                'data'=>$data,
                'info'=>$list,
                'housedatails'=> $housedetails,
            ]);
        }else{
           //显示别墅端
            return view('villa/index',[
                'data'=>$data,
                'info'=>$list,
                'housedatails'=> $housedetails,
            ]);
        }

    }

    /**
     *  显示二级分页之宾馆分页
     */
    public function hotiallindex()
    {

        //从数据库导出导航条数据
        $list = Db::name('index_navigation')->select();
        //从数据库里查询友情链接
        $data = Db::table('lt_link')->select();

        //从房屋详情表中取出房屋数据
        $housedetails = Db::table('lt_house_details')->where('housetype','42')->where('checking','<>','2')->select();

        if(is_mobile()){
            //显示手机端
            return view('villa/Mhotial',[
                'data'=>$data,
                'info'=>$list,
                'housedatails'=> $housedetails,
            ]);
        }else{
            //显示pc端
            return view('villa/hotial',[
                'data'=>$data,
                'info'=>$list,
                'housedatails'=> $housedetails,
            ]);
        }

    }


    /**
     * 显示民房首页
     */

    public function citizen()
    {
        //从数据库导出导航条数据
        $list = Db::name('index_navigation')->select();
        //从数据库里查询友情链接
        $data = Db::table('lt_link')->select();

        //从房屋详情表中取出房屋数据
        $housedetails = Db::table('lt_house_details')->where('housetype','43')->where('checking','<>','2')->select();

        if(is_mobile()){
            //显示手机端
            return view('villa/Mcitizen',[
                'data'=>$data,
                'info'=>$list,
                'housedatails'=> $housedetails,
            ]);
        }else{
            //显示pc端
            return view('villa/citizen',[
                'data'=>$data,
                'info'=>$list,
                'housedatails'=> $housedetails,
            ]);
        }

    }















    /**
     * 显示商品详情页详情
     *
     * @return \think\Response
     */
    public function detail($id)
    {
        if(Session::get('login_admin.id')){$user_id=Session::get('login_admin.id');}else{$user_id=Session::get('login_tel.id');}
        //从数据库导出导航条数据
        $list = Db::name('index_navigation')->select();
        //从数据库里查询友情链接
        $data = Db::table('lt_link')->select();
        //跟据用户的id查出房屋详情表
        $result = Db::table('lt_house_details')->where('id',$id)->find();
         $str=$result['houseserver'];
        $arr= explode(',',$str);
        //根据房源分类(居家)表查出所属的服务
        $houseserver = Db::table('lt_fixing_service')->wherein('id',$arr)->select();


        //根据房源分类(卫浴)表查出所属的服务
        $str1=$result['bathserver'];
        $arr1= explode(',',$str1);
        $bathserver = Db::table('lt_fixing_service')->wherein('id',$arr1)->select();

        //根据房源分类(餐厨)表查出所属的服务
        $str2=$result['wasteserver'];
        $arr2= explode(',',$str2);
        $wasteserver = Db::table('lt_fixing_service')->wherein('id',$arr2)->select();

        //根据房源分类（推荐入住人数）查出所属的服务
        $str3 = $result['total'];
        $arr3 = explode(',',$str3);
        $total = Db::table('lt_fixing_service')->wherein('id',$arr3)->select();

        //根据房源分类（提供）查出所属的服务
        $str4 = $result['provide'];
        $arr4 = explode(',',$str4);
        $provide = Db::table('lt_fixing_service')->wherein('id',$arr4)->select();

        //根据房源分类（多久对房间打扫一次）查出所属的服务
        $str5 = $result['clean'];
        $arr5 = explode(',',$str5);
        $clean = Db::table('lt_fixing_service')->wherein('id',$arr5)->select();

        $comment = Db::table('lt_house_details')
            ->alias('a')
            ->join('lt_order_detials w','a.id = w.house_id')
            ->join('lt_user_reviews t', 'w.id = t.order_id')
            ->where('t.user_id',$user_id)
            ->select();


        $reply = Db::table('lt_order_detials')
            ->alias('b')
            ->join('lt_user_reviews t', 'b.id = t.order_id')
            ->join('lt_user_reply h', 't.id = h.comment_id')
            ->where('h.user_id',$user_id)
            ->select();

        foreach($comment as $val){
            $info[] = $val['house_name'];
        }

       if(is_mobile()){
           //显示手机端
           return view('villa/Mdetail',[
               'data'=>$data,
               'info'=>$list,
               'result'=>$result,
               'houseserver'=>$houseserver,
               'bathserver'=>$bathserver,
               'wasteserver'=>$wasteserver,
               'total'=>$total,
               'provide'=>$provide,
               'clean'=>$clean,
               'time1'=>date('Y-m-d',time()),
               'time2'=>date('Y-m-d',time()+86400),
               'comment'=>$comment,
               'reply'=>$reply,
               'info1'=>isset($info) ? $info : '',
           ]);
       }else{
           //显示pc端
           return view('villa/detail',[
               'data'=>$data,
               'info'=>$list,
               'result'=>$result,
               'houseserver'=>$houseserver,
               'bathserver'=>$bathserver,
               'wasteserver'=>$wasteserver,
               'total'=>$total,
               'provide'=>$provide,
               'clean'=>$clean,
               'time1'=>date('Y-m-d',time()),
               'time2'=>date('Y-m-d',time()+86400),
               'comment'=>$comment,
               'reply'=>$reply,
               'info1'=>isset($info) ? $info : '',
           ]);
       }


    }

    public function linkphone(Request $request)
    {
        //查询商家详情表 联系电话
        $link_name = Request::instance()->param('link_name');

        $data = Db::table('lt_goods_details')->where('link_name',$link_name)->field('link_phone')->select();
        return json($data[0]['link_phone']);
    }


}
